<?php

namespace Biz\model;

use Doraemon\pockets\datebase\BaseDbModel;

class ShopAuth extends BaseDbModel
{
    const _CONFIG_FILE_ = 'db_shop';

    const _CONFIG_SELECT_ = 'db_shop_info';

    const _DATABASE_ = 'shop_info';

    const _TABLE_NAME = 'shop_auth';

    const _SUB_TABLE = false;

    const STATUS_DISABLED = 0;//失效状态

    const STATUS_NORMAL = 1;//正常状态

    public static function getAuthInfo($email)
    {
        return self::get('*', [
            'status' => self::STATUS_NORMAL,
            'email' => $email
        ]);
    }

    public static function getAuthInfoByUid($uid)
    {
        return self::get('*', [
            'status' => self::STATUS_NORMAL,
            'uid' => $uid
        ]);
    }

    public static function getEmail($uid)
    {
        return self::get('email', [
            'status' => self::STATUS_NORMAL,
            'uid' => $uid
        ]);
    }

    public static function getUid($email, $password)
    {
        return self::get('uid', [
            'status' => self::STATUS_NORMAL,
            'email' => $email,
            'password' => $password
        ]);
    }

    public static function getByUid($uid)
    {
        return self::get('*', [
            'uid' => $uid,
        ]);
    }

    public static function getEmailByUid($uid)
    {
        return self::get('email', [
            'uid' => $uid,
        ]);
    }

    public static function getByEmail($email)
    {
        return self::get('*', [
            'email' => $email,
        ]);
    }

    public static function addInfo($data)
    {
        self::insert($data);
        return self::id();
    }

    public static function updateInfo($data, $where)
    {
        $result = self::update($data, $where);
        return $result->rowCount();
    }

    public static function hasInfo($where)
    {
        return self::has($where);
    }
}